//
//  LGSportsTrainEvaluationView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/10.
//

#import "LGSportsTrainMineEvaView.h"

@interface LGSportsTrainMineEvaView() 
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIView *topView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIButton *cancelBtn;
/**   */
@property (nonatomic , strong)UIButton *sureBtn;


@end

@implementation LGSportsTrainMineEvaView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.baseView];
        [self.baseView addSubview:self.topView];
        [self.topView addSubview:self.titleLabel];
        [self.topView addSubview:self.cancelBtn];
        [self.topView addSubview:self.sureBtn];
    }
    return self;
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    CGFloat topMargin = viewPix(65);
    for (NSInteger i=0; i<dataArray.count; i++) {
        NSDictionary *tempDic = dataArray[i];
        CGFloat titleHeight = [LGNSString(tempDic[@"title"]) textHeightWithFont:LGFont(16) maxWidth:Screen_W-viewPix(40)];
        UILabel *titleLabel = [UILabel lableWithText:LGNSString(tempDic[@"title"]) colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
        titleLabel.frame = CGRectMake(viewPix(24), topMargin, Screen_W-viewPix(40), titleHeight);
        [self.baseView addSubview:titleLabel];
        
        
        CGFloat contentHeight = [LGNSString(tempDic[@"answer"]) textHeightWithFont:LGFont(16) maxWidth:Screen_W-viewPix(40)];
        UILabel *contentLabel = [UILabel lableWithText:LGNSString(tempDic[@"answer"]) colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:0];
        contentLabel.frame = CGRectMake(viewPix(24), kMaxY(titleLabel.frame)+viewPix(12), Screen_W-viewPix(40), contentHeight);
        [self.baseView addSubview:contentLabel];
        topMargin = kMaxY(contentLabel.frame)+viewPix(24);
    }
    CGFloat height = topMargin+viewPix(70);
    self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, height);
    [self showPickView];
}

-(void)showPickView{
    [UIView animateWithDuration:0.3 animations:^{
        CGFloat height = self.baseView.bounds.size.height;
        self.baseView.frame = CGRectMake(0, Screen_H-height+viewPix(20), Screen_W, height);
        self.backgroundColor = RGBAColor(0, 0, 0, 0.3);
    }];
}

-(void)hiddenPickView{
    [UIView animateWithDuration:0.3 animations:^{
        CGFloat height = self.baseView.bounds.size.height;
        self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, height);
        self.backgroundColor =  RGBAColor(0, 0, 0, 0);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(233)+bottomSafeBarHeight)];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(UIView *)topView{
    if(!_topView){
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 45*LGPercent)];
        _topView.backgroundColor = [UIColor whiteColor];
        _topView.cornerRidus = 10;
    }
    return _topView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#000000" textFont:LGFont(15) textAlignment:NSTextAlignmentCenter lines:1];
        _titleLabel.frame = CGRectMake(viewPix(60), viewPix(5), Screen_W-viewPix(120), viewPix(40));
    }
    return _titleLabel;
}

-(UIButton *)cancelBtn{
    if(!_cancelBtn){
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.frame = CGRectMake(0, viewPix(5), 60*LGPercent, 40*LGPercent);
        _cancelBtn.titleLabel.font = LGFontWeight(14, UIFontWeightSemibold);
        [_cancelBtn setTitleColor:[UIColor colorWithString:@"#999999"] forState:UIControlStateNormal];
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn addTarget:self action:@selector(hiddenPickView) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

-(UIButton *)sureBtn{
    if(!_sureBtn){
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _sureBtn.frame = CGRectMake(Screen_W - 60*LGPercent, viewPix(5), 60*LGPercent, 40*LGPercent);
        _sureBtn.titleLabel.font = LGFontWeight(14, UIFontWeightSemibold);
        [_sureBtn setTitleColor:[UIColor colorWithString:@"#429BFF"] forState:UIControlStateNormal];
        [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_sureBtn addTarget:self action:@selector(hiddenPickView) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureBtn;
}

@end
